package com.ky.serialport.sensor;

import static com.ky.serialport.utils.FormatUtils.df3;
import static com.ky.serialport.utils.MyFunc.ArryToFloat;

/**
 * 405_410
 */
public class Dt405_410DataBean {
    public Long time = 0L;
    public float fengsuVel = 0; //风速值
    public float wenduVel = 0; //温度值
    public float dqyVel = 1013.25f; //标准大气压值
    public float aVel = 0L;
    public float bVel = 1L;
    public float cVel = 0L;

    public Dt405_410DataBean() {
    }

    /**
     * 设置校准风速的时候用此构造函数
     * @param aVel
     * @param bVel
     * @param cVel
     */
    public Dt405_410DataBean(float aVel , float bVel , float cVel) {
        this.aVel = aVel;
        this.bVel = bVel;
        this.cVel = cVel;
    }

    /**
     * 设置校准系数 res = aVel * X * X + bVel * X + cVel ；
     * @param aVel
     * @param bVel
     * @param cVel
     */
    public void setXiShu(float aVel , float bVel , float cVel) {
        this.aVel = aVel;
        this.bVel = bVel;
        this.cVel = cVel;
    }

    /**
     * 计算风速
     * @param buffer 数据包
     * @param dqyVel 实时大气压
     * @return
     */
    public Dt405_410DataBean caculateFengSu(byte[] buffer, float dqyVel) {
        caculateFS(buffer,dqyVel);
        return this;
    }

    public Dt405_410DataBean caculateFengSu(byte[] buffer) {
        caculateFS(buffer,dqyVel);
        return this;
    }


    public void caculateFS(byte[] buffer, float dqyVel) {

        float c = Float.valueOf(df3.format(ArryToFloat(buffer, 0)));
        float d = c * 1013.25f / dqyVel;

        if (c <= 0) {
            fengsuVel = 0;
        } else {
            float y = aVel * d * d + bVel * d + cVel;
            fengsuVel = y <= 0 ? 0 : y;
        }
    }

    /**
     * 计算温度
     * @param buffer
     * @return
     */
    public Dt405_410DataBean caculateWenDu(byte[] buffer) {
        wenduVel = ArryToFloat(buffer, 3);
        return this;
    }

}
